/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef _AUDIO_PROCESSING_DRC_INCLUDE_DYNAMIC_RANGE_COMPRESSION_H_
#define _AUDIO_PROCESSING_DRC_INCLUDE_DYNAMIC_RANGE_COMPRESSION_H_

#include <stddef.h>
#include <stdint.h>
/* #include "webrtc/typedefs.h" */

typedef struct DrcHandleT DrcHandle;

#ifdef __cplusplus
extern "C" {
#endif

/*
 * This function creates an instance of Dynamic Range Compression.
 */
DrcHandle* Drc_Create();

/*
 * This function frees the dynamic memory of a dynamic range compression
 * instance.
 *
 * Input:
 *      - DRC_inst       : Pointer to DRC instance that should be freed
 */
void Drc_Free(DrcHandle* DRC_inst);

/*
 * This function initializes a DRC instance and has to be called before any other
 * processing is made.
 *
 * Input:
 *      - DRC_inst       : Instance that should be initialized
 *      - fs            : sampling frequency
 *      - threshold1    : drc energy threshold, must more than threshold2
 *      - ratio         : drc ratio
 *      - threshold2    : inverse drc energy threshold, must less than threshold1 
 *      - mode          : 0, drc; 1 inverse drc
 *      - supPoint      : 0~1 [maxFrequency*supPoint, maxFrequency]
 *      - supExp        : pow(p, supExp) p=(maxFrequency-i)/(maxFrequency-maxFrequency*supPoint)
 *
 * Output:
 *      - DRC_inst       : Initialized instance
 *
 * Return value         :  0 - Ok
 *                        -1 - Error
 */
int Drc_Init(DrcHandle* DRC_inst, uint32_t fs, int threshold1, float ratio, int threshold2, int mode, float supPoint, float supExp);

/*
 * This functions does Dynamic Range Compression for the inserted speech frame. The
 * input and output signals should always be 10ms (80 or 160 samples).
 *
 * Input
 *      - DRC_inst       : Dynamic Range Compression instance.
 *      - spframe       : Pointer to speech frame buffer for each band
 *
 * Output:
 *      - DRC_inst       : Updated DRC instance
 *      - outframe      : Pointer to output frame for each band
 */
void Drc_Process(DrcHandle* DRC_inst,
                     const float* const* spframe,
                     float* const* outframe);

#ifdef __cplusplus
}
#endif

#endif  // _AUDIO_PROCESSING_DRC_INCLUDE_DYNAMIC_RANGE_COMPRESSION_H_
